<template>
  <el-dialog title="请选择筛选项" :visible.sync="currentValue" width="430px">
    <div style="margin-top: 20px">
      <el-checkbox
        :indeterminate="isIndeterminate"
        v-model="checkAll"
        @change="handleCheckAllChange"
      >
        全选
      </el-checkbox>
      <div style="margin: 15px 0;"></div>
      <el-checkbox-group
        v-model="checkedItems"
        @change="handleCheckedCitiesChange"
      >
        <el-checkbox v-for="item in items" :label="item" :key="item">
          {{ item }}
        </el-checkbox>
      </el-checkbox-group>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="currentValue = false">取 消</el-button>
      <el-button type="primary" @click="makeSure">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import ZvModel from '@/mixins/zv-model'
export default {
  name: 'FiltrateView',
  mixins: [ZvModel],
  data() {
    return {
      isIndeterminate: true,
      checkAll: false,
      items: ['未处理', '已处理', '已关闭'],
      checkedItems: ['未处理', '已处理']
    }
  },
  methods: {
    handleCheckAllChange(val) {
      this.checkedItems = val ? this.items : []
      this.isIndeterminate = false
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length
      this.checkAll = checkedCount === this.items.length
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.items.length
    },
    makeSure() {
      this.currentValue = false
      if (this.checkedItems.length) {
        this.$emit('selectItem', this.checkedItems)
      }
    }
  }
}
</script>
